package com.cn.unarmed.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;

import com.cn.unarmed.adapter.ListChildAdapter;
import com.cn.unarmed.base.BaseActivity;
import com.cn.unarmed.bean.DataHolder;
import com.cn.unarmed.commonutils.AppUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试有子列表的listView
 */
public class ChildListViewActivity extends BaseActivity {

    ExpandableListView ex_listView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_child_list_view);

        setTitle(getString(R.string.child_list_title));
        setNavBtn(R.mipmap.back_arrow, 0);
        initView();
    }

    private void initView() {

        ex_listView = (ExpandableListView) this.findViewById(R.id.ex_listView);

        List<DataHolder> list_parent = new ArrayList<>();
        DataHolder data;
        List<String> data_child = new ArrayList<>();
        data_child.add("大虾");
        data_child.add("打下");
        data_child.add("大侠");
        for (int i = 0; i < 3; i++) {
            data = new DataHolder("大夏", "大夏", data_child);
            list_parent.add(data);
        }
        List<String> data_child_none = new ArrayList<>();
        data = new DataHolder("尼玛", "大夏", data_child_none);
        list_parent.add(data);
        data = new DataHolder("滚粗", "大夏", data_child);
        list_parent.add(data);
        final ListChildAdapter child = new ListChildAdapter(this, list_parent, ex_listView);
        ex_listView.setGroupIndicator(null);
        ex_listView.setDivider(null);
        ex_listView.setAdapter(child);

//      默认展开
//        for (int i = 0; i < child.getGroupCount(); i++) {
//            ex_listView.expandGroup(i);
//        }

        ex_listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
            @Override
            public void onGroupExpand(int groupPosition) {
                for (int i = 0; i < child.getGroupCount(); i++) {
                    if (groupPosition != i) {
                        ex_listView.collapseGroup(i);
                    }
                }
                AppUtils.showToast(ChildListViewActivity.this,
                        "第" + String.valueOf(groupPosition + 1) + "条展开了", true);
            }
        });
    }

    @Override
    protected void HandleTitleBarEvent(TitleBar component, View v) {
        if (component.equals(TitleBar.TITLE)) {
            AppUtils.showToast(this, "你丫点到我了", false);
        }
    }
}
